package com.ruoyi.funding.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.funding.mapper.ReimbursementMapper;
import com.ruoyi.funding.domain.Reimbursement;
import com.ruoyi.funding.service.IReimbursementService;

import static com.ruoyi.common.core.context.SecurityContextHolder.getUserName;

/**
 * 报销记录Service业务层处理
 * 
 * @author ycl
 * @date 2025-01-06
 */
@Service
public class ReimbursementServiceImpl implements IReimbursementService 
{
    @Autowired
    private ReimbursementMapper reimbursementMapper;

    /**
     * 查询报销记录
     * 
     * @param reimbursementId 报销记录主键
     * @return 报销记录
     */
    @Override
    public Reimbursement selectReimbursementByReimbursementId(Long reimbursementId)
    {
        return reimbursementMapper.selectReimbursementByReimbursementId(reimbursementId);
    }

    /**
     * 查询报销记录列表
     * 
     * @param reimbursement 报销记录
     * @return 报销记录
     */
    @Override
    public List<Reimbursement> selectReimbursementList(Reimbursement reimbursement)
    {
        return reimbursementMapper.selectReimbursementList(reimbursement);
    }

    /**
     * 新增报销记录
     * 
     * @param reimbursement 报销记录
     * @return 结果
     */
    @Override
    public int insertReimbursement(Reimbursement reimbursement)
    {
        reimbursement.setCreateTime(DateUtils.getNowDate());
        reimbursement.setCreateBy(getUserName());
        return reimbursementMapper.insertReimbursement(reimbursement);
    }

    /**
     * 修改报销记录
     * 
     * @param reimbursement 报销记录
     * @return 结果
     */
    @Override
    public int updateReimbursement(Reimbursement reimbursement)
    {
        reimbursement.setUpdateTime(DateUtils.getNowDate());
        reimbursement.setUpdateBy(getUserName());
        return reimbursementMapper.updateReimbursement(reimbursement);
    }

    /**
     * 批量删除报销记录
     * 
     * @param reimbursementIds 需要删除的报销记录主键
     * @return 结果
     */
    @Override
    public int deleteReimbursementByReimbursementIds(Long[] reimbursementIds)
    {
        for (Long reimbursementId : reimbursementIds){
            Reimbursement reimbursement = reimbursementMapper.selectReimbursementByReimbursementId(reimbursementId);
            reimbursement.setDeleteTime(DateUtils.getNowDate());
            reimbursement.setDeleteBy(getUserName());
            reimbursementMapper.updateReimbursement(reimbursement);
        }
        return reimbursementMapper.deleteReimbursementByReimbursementIds(reimbursementIds);
    }

    /**
     * 删除报销记录信息
     * 
     * @param reimbursementId 报销记录主键
     * @return 结果
     */
    @Override
    public int deleteReimbursementByReimbursementId(Long reimbursementId)
    {
        Reimbursement reimbursement = reimbursementMapper.selectReimbursementByReimbursementId(reimbursementId);
        reimbursement.setDeleteTime(DateUtils.getNowDate());
        reimbursement.setDeleteBy(getUserName());
        reimbursementMapper.updateReimbursement(reimbursement);
        return reimbursementMapper.deleteReimbursementByReimbursementId(reimbursementId);
    }
}
